<%@ page import="org.springframework.context.ApplicationContext" %>
<%@ page import="static org.apache.struts2.ServletActionContext.getServletContext" %>
<%@ page import="org.springframework.web.context.WebApplicationContext" %>
<%@ page import="com.ld.xuanKe.service.impl.CourseServiceImpl" %>
<%@ page import="com.ld.xuanKe.service.CourseService" %>
<%@ page import="com.ld.xuanKe.entity.Course" %><%--
  Created by IntelliJ IDEA.
  User: 刘邓
  Date: 2023-12-09
  Time: 17:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
  <title>增加课程信息</title>
  <link rel="stylesheet" type="text/css" href="/form.css" />
</head>
<body>
<%
  ApplicationContext applicationContext = (ApplicationContext) getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
  CourseService courseService = (CourseServiceImpl) applicationContext.getBean(CourseService.class);
  Integer id = Integer.parseInt(request.getParameter("id"));
  Course course = courseService.querySingle(id);
%>
<form action="/course/update" class="container">

  <h2>修改课程信息</h2>
  <input type="text" name="id" value="<%=course.getId()%>" class="form-control" hidden>
  <div class="form-group">

    <label for="name">课程名:</label>

    <input type="text" name="name" value="<%=course.getName()%>" id="name" class="form-control">

  </div>

  <div class="form-group">

    <label for="teacher">授课教师:</label>

    <input type="text" name="teacher" id="teacher" value="<%=course.getTeacher()%>" class="form-control">

  </div>

  <div class="form-group">

    <label for="capacity">容量:</label>

    <input type="number" name="capacity" id="capacity" value="<%=course.getCapacity()%>" class="form-control">

  </div>
  <div class="form-group">

    <label for="capacity">已选人数:</label>

    <input type="number" name="selected" id="selected" value="<%=course.getSelected()%>" class="form-control">

  </div>

  <div class="form-group">

    <label for="s_time">开始时间:</label>

    <input type="datetime-local" min="00:00" max="23:59" value="<%=course.getStartTime()%>" name="startTime0" id="s_time" class="form-control">

  </div>

  <div class="form-group">

    <label for="e_time">结束时间:</label>

    <input type="datetime-local" min="00:00" max="23:59" name="endTime0" value="<%=course.getEndTime()%>" id="e_time" class="form-control">

  </div>
  <div class="form-group">

    <label for="bz">课程说明:</label>

    <input name="bz" id="bz" class="form-control" value="<%=course.getBz()%>">

  </div>
  <div class="form-group">

    <label for="bz">学分:</label>

    <input name="xf" id="xf" class="form-control" value="<%=course.getXf()%>">

  </div>

  <div style="text-align: center">

    <button type="submit" id="toUpdate" style="width: 100px;height: 50px;background-color: #fff" class="btn btn-primary">提交</button>

  </div>

</form>

</body>
<script>
  let toUpdate = document.getElementById("toUpdate");
  toUpdate.addEventListener("click",(evt)=>{
    let name_str=document.getElementById("name").value;
    if(name_str===null||name_str===""){
      alert("请输入课程名");
      evt.preventDefault();
      return;
    }
    let teacher_str=document.getElementById("teacher").value;
    if(teacher_str===null||teacher_str===""){
      alert("请输入授课教师名字");
      evt.preventDefault();
      return;
    }
    let capacity_str=document.getElementById("capacity").value;
    if(capacity_str===null||capacity_str===""){
      alert("请输入容量");
      evt.preventDefault();
      return;
    }
    let selected_str=document.getElementById("selected").value;
    if(selected_str===null||selected_str===""){
      alert("请输入已选人数");
      evt.preventDefault();
      return;
    }
    let bz_str=document.getElementById("bz").value;
    if(bz_str===null||bz_str===""){
      alert("请输入课程说明");
      evt.preventDefault();
      return;
    }
    let xf_str=document.getElementById("xf").value;
    if(xf_str===null||xf_str===""){
      alert("请输入课程学分");
      evt.preventDefault();
      return;
    }
  })
</script>
</html>
